<?php

namespace App\Http\Controllers\Backend;

use App\Logics\CaptchaLogic;
use App\Manage\AccountManage;
use App\Manage\CacheManage;


class AccountController extends BaseController
{
    // 个人账户

    // 初始化
    public function initialize()
    {
        parent::initialize();
    }

    // 获取登录用户信息
    public function info()
    {
        $logic = new AccountManage();
        $res   = $logic->info($this->myUid);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 修改
    public function edit()
    {
        if(empty($this->myUser)){
            //return $this->error('请登录后在操作！！', [], LOGIN_ERROR);
            return $this->error('please_login_before_operation', [], LOGIN_ERROR);
        }

        // 修改
        $logic = new AccountManage();
        $res   = $logic->edit($this->myUser);
        if($res === false){
            return $this->error($logic->getError());
        }


        return $this->success();
    }

    // 修改密码
    public function password()
    {
        if(empty($this->myUser)){
            //return $this->error('请登录后在操作！！', [], LOGIN_ERROR);
            return $this->error('please_login_before_operation', [], LOGIN_ERROR);
        }

        // 修改
        $logic = new AccountManage();
        $res   = $logic->password($this->myUser);
        if($res === false){
            return $this->error($logic->getError());
        }


        return $this->success();
    }

    // 登录
    public function login()
    {
        $logic = new AccountManage();
        $res   = $logic->login();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 删除缓存
    public function clear()
    {
        $logic = new CacheManage();
        $res   = $logic->clear($this->myUser);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 生成token
    public function token()
    {
        $logic = new AccountManage();
        $res   = $logic->token();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    //  查询测试
    // http://www.shop.com/account/captcha/click
    public function click()
    {
        $logic = new CaptchaLogic();
        $res   = $logic->clickCaptcha();

        return $this->success($res);
    }

    /**
     * 点选验证码检查：验证
     */
    public function checkClick()
    {
        $logic = new CaptchaLogic();
        $res   = $logic->checkClickCaptcha();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success();
    }

    // 生成验证码
    public function captcha()
    {
        $logic = new AccountManage();
        $res   = $logic->captcha();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $res;
    }

    // 退出
    public function logout()
    {
        return $this->success();
    }


}


